﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpringStudio.DAL.PaginationHandler
{
    /// <summary>
    /// 分页参数验证方法类
    /// </summary>
    internal static class PaginationValidationCheck
    {
        /// <summary>
        /// 判断排序字段集合中是否存在某个主键字段名
        /// </summary>
        /// <param name="orderFields">排序字段集合</param>
        /// <param name="primaryKey">主键字段名</param>
        /// <returns>是否</returns>
        internal static bool IsOrderFieldsContainPrimaryKey(List<PaginationOrderField> orderFields, string primaryKey)
        {
            foreach (PaginationOrderField orderField in orderFields)
            {
                if (orderField.FieldName.Trim().ToLower() == primaryKey.Trim().ToLower())
                {
                    return true;
                }
            }

            return false;
        }

        /// <summary>
        /// 判断主键字段集合中是否存在某个排序字段
        /// </summary>
        /// <param name="primaryKeys">主键字段集合</param>
        /// <param name="orderField">排序字段对象</param>
        /// <returns>是否</returns>
        internal static bool IsPrimaryKeysContainOrderField(List<string> primaryKeys, PaginationOrderField orderField)
        {
            foreach (string primaryKey in primaryKeys)
            {
                if (orderField.FieldName.Trim().ToLower() == primaryKey.Trim().ToLower())
                {
                    return true;
                }
            }

            return false;
        }
    }
}
